{include file="public/header" /}
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/webuploader.css">
<link rel="stylesheet" type="text/css" href="/static/admin/webupload/style.css">
<style>
    .file-item{float: left; position: relative; width: 110px;height: 110px; margin: 0 20px 20px 0; padding: 4px;}
    .file-item .info{overflow: hidden;}
    .uploader-list{width: 100%; overflow: hidden;}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加微信公众号</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add" id="add" method="post" action="{:url('wechat_edit')}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">Token：</label>
                            <div class="input-group col-sm-4">
                                <input id="token" type="text" class="form-control" name="token" value="{$wechat.token}">
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">公众号名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="wechat_name" type="text" class="form-control" name="wechat_name"  value="{$wechat.wechat_name}"   >
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">公众号原始id：</label>
                            <div class="input-group col-sm-4">
                                <input id="original_id" type="text" class="form-control" name="original_id"  value="{$wechat.original_id}" >
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">微信号：</label>
                            <div class="input-group col-sm-4">
                                <input id="wechat_id" type="text" class="form-control" name="wechat_id"  value="{$wechat.wechat_id}" >
                            </div>
                        </div>






                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">头像地址：</label>
                            <div class="input-group col-sm-4">
                                <input type="hidden" id="data_photo" name="head_img"  value="{$wechat.head_img}">
                                <div id="fileList" class="uploader-list" style="float:right"></div>
                                <div id="imgPicker" style="float:left">选择头像</div>
                                <img id="img_data" class="img-circle" height="80px" width="80px" style="float:left;margin-left: 50px;margin-top: -10px;"    src="/uploads/face/{$wechat.head_img}" onerror="this.src='/static/admin/images/head_default.gif'"  />
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">appid：</label>
                            <div class="input-group col-sm-4">
                                <input id="appid" type="text" class="form-control" name="appid"  value="{$wechat.appid}" >

                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">encodingaeskey：</label>
                            <div class="input-group col-sm-4">
                                <input id="encodingaeskey" type="text" class="form-control" name="encodingaeskey"  value="{$wechat.encodingaeskey}" >
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">appsecret：</label>
                            <div class="input-group col-sm-4">
                                <input id="appsecret" type="text" class="form-control" name="appsecret"  value="{$wechat.appsecret}" >
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">二维码：</label>
                            <div class="input-group col-sm-4">
                                <input type="hidden" id="data_photo1" name="erweima"  value="{$wechat.erweima}" >
                                <div id="fileList1" class="uploader-list" style="float:right"></div>
                                <div id="imgPicker1" style="float:left">选择头像</div>
                                <img id="img_data1" class="img-circle" height="80px" width="80px" style="float:left;margin-left: 50px;margin-top: -10px;"  src="/uploads/face/{$wechat.erweima}" onerror="this.src='/static/admin/images/head_default.gif'"  />
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">微信号类型：</label>
                            <div class="input-group col-sm-4">
                                <select class="form-control m-b chosen-select" name="type" id="type">
                                    <option {if condition="$wechat.type ==1"}selected{/if} value="1">订阅号</option>
                                    <option {if condition="$wechat.type ==2"}selected{/if} value="2">认证订阅号</option>
                                    <option {if condition="$wechat.type ==3"}selected{/if} value="3">服务号</option>
                                    <option {if condition="$wechat.type ==4"}selected{/if} value="4">认证服务号</option>
                                </select>
                            </div>
                        </div>



                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">关注回复：</label>
                            <div class="input-group col-sm-4">
                                <textarea name="focus_repay" class="form-control" rows="5" style="width: 300px;">{$wechat.focus_repay}</textarea>
                            </div>
                        </div>

                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">默认回复：</label>
                            <div class="input-group col-sm-4">
                                <textarea name="default_repay" class="form-control" rows="5" style="width: 300px;">{$wechat.default_repay}</textarea>
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">接入状态：</label>
                            <div class="col-sm-6">
                                <div class="radio ">
                                    <input type="checkbox" name='status'  value="{$wechat.status}" class="js-switch" checked />&nbsp;&nbsp;默认开启
                                </div>
                            </div>
                        </div>


                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <input  type="hidden" class="form-control" name="id"  value="{$wechat.id}" >
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}
<script type="text/javascript" src="/static/admin/webupload/webuploader.min.js"></script>

<script type="text/javascript">
    var $list = $('#fileList');
    //上传图片,初始化WebUploader
    var uploader = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Upload/uploadface')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo").val(data._raw);
            $("#img_data").attr('src', '/uploads/face/' + data._raw).show();
        }
    });

    uploader.on( 'fileQueued', function( file ) {
//        $list.html( '<div id="' + file.id + '" class="item">' +
//                '<h4 class="info">' + file.name + '</h4>' +
//                '<p class="state">正在上传...</p>' +
//                '</div>' );
    });

    // 文件上传成功
    uploader.on( 'uploadSuccess', function( file ) {
//        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });




    var uploader1 = WebUploader.create({

        auto: true,// 选完文件后，是否自动上传。
        swf: '/static/admin/webupload/Uploader.swf',// swf文件路径
        server: "{:url('Upload/uploadface')}",// 文件接收服务端。
        duplicate :true,// 重复上传图片，true为可重复false为不可重复
        pick: '#imgPicker1',// 选择文件的按钮。可选。

        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/jpg,image/jpeg,image/png'
        },

        'onUploadSuccess': function(file, data, response) {
            $("#data_photo1").val(data._raw);
            $("#img_data1").attr('src', '/uploads/face/' + data._raw).show();
        }
    });

    uploader1.on( 'fileQueued', function( file ) {
//        $list.html( '<div id="' + file.id + '" class="item">' +
//                '<h4 class="info">' + file.name + '</h4>' +
//                '<p class="state">正在上传...</p>' +
//                '</div>' );
    });

    // 文件上传成功
    uploader1.on( 'uploadSuccess', function( file ) {
//        $( '#'+file.id ).find('p.state').text('上传成功！');
    });

    // 文件上传失败，显示上传出错。
    uploader1.on( 'uploadError', function( file ) {
        $( '#'+file.id ).find('p.state').text('上传出错!');
    });



    //提交
    $(function(){
        $('#add').ajaxForm({
            beforeSubmit: checkForm,
            success: complete,
            dataType: 'json'
        });

        function checkForm(){
//            if( '' == $.trim($('#username').val())){
//                layer.msg('请输入用户名',{icon:2,time:1500,shade: 0.1}, function(index){
//                    layer.close(index);
//                });
//                return false;
//            }
//
//            if( '' == $.trim($('#groupid').val())){
//                layer.msg('请选择用户角色',{icon:2,time:1500,shade: 0.1}, function(index){
//                    layer.close(index);
//                });
//                return false;
//            }
//
//            if( '' == $.trim($('#password').val())){
//                layer.msg('请输入登录密码',{icon:2,time:1500,shade: 0.1}, function(index){
//                    layer.close(index);
//                });
//                return false;
//            }
//
//            if( '' == $.trim($('#real_name').val())){
//                layer.msg('请输入真实姓名',{icon:2,time:1500,shade: 0.1}, function(index){
//                    layer.close(index);
//                });
//                return false;
//            }
        }


        function complete(data){

            if(data.code==11){
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;
            }else{
                if(data.code==1){
                    layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                        window.location.href="{:url('wechat/index')}";
                    });
                }else{
                    layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                    return false;
                }
            }



        }

    });



    //IOS开关样式配置
    var elem = document.querySelector('.js-switch');
    var switchery = new Switchery(elem, {
        color: '#1AB394'
    });
    var config = {
        '.chosen-select': {},
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>